//
//  StatusOriginalView.swift
//  Weibo
//
//  Created by 张小东 on 16/1/18.
//  Copyright © 2016年 Mr.Zhang. All rights reserved.
//

import UIKit
import SnapKit

class StatusOriginalView: UIView {
    
    var statuses: Status? {
        didSet {
            // 绑定数据
            headImage.sd_setImageWithURL(statuses?.user?.headImageURL,placeholderImage: UIImage(named: "avatar_default_big"))
            nameLabel.text = statuses?.user?.name
            mbrankImage.image = statuses?.user?.mbrank_image
            verifiedTypeImage.image = statuses?.user?.verified_type_image
            timeLabel.text = statuses?.created_at
            sourceLabel.text = statuses?.source
            contentLabel.text = statuses?.text
            // 传递配图视图的数据源
            pictureView.imageURLs = statuses?.imageURLs
            
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        addSubview(headImage)
        addSubview(nameLabel)
        addSubview(mbrankImage)
        addSubview(sourceLabel)
        addSubview(timeLabel)
        addSubview(contentLabel)
        addSubview(verifiedTypeImage)
        addSubview(pictureView)
        // 设置约束
        headImage.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top).offset(StatusCellMargin)
            make.left.equalTo(self.snp_left).offset(StatusCellMargin)
            make.size.equalTo(CGSize(width: StatusCellImageWidth, height: StatusCellImageWidth))
        }
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(headImage.snp_top)
            make.left.equalTo(headImage.snp_right).offset(StatusCellMargin)
        }
        mbrankImage.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(nameLabel.snp_top)
            make.left.equalTo(nameLabel.snp_right).offset(StatusCellMargin)
        }
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(headImage.snp_bottom)
            make.left.equalTo(headImage.snp_right).offset(StatusCellMargin)
        }
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(timeLabel.snp_top)
            make.left.equalTo(timeLabel.snp_right).offset(StatusCellMargin)
        }
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(headImage.snp_left)
            make.top.equalTo(headImage.snp_bottom).offset(StatusCellMargin)
        }
        verifiedTypeImage.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(headImage.snp_right)
            make.centerY.equalTo(headImage.snp_bottom)
        }
        pictureView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(contentLabel.snp_left)
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
         
            // make.height.width.equalTo(100)
            //c  测试大小
            make.size.equalTo(CGSize(width: 100, height: 100))
        }
        
        
        
        // 设置 StatusOriginalView的底部与pictureView底部的约束 就能实现行高的自动获取
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin)
        }
    }
    
    // 添加子视图
    private lazy var headImage: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    private lazy var nameLabel: UILabel = UILabel(title: "暗夜猎手", fontSize: 14, color: UIColor.orangeColor())
    //VIP 图标
    private lazy var mbrankImage: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    private lazy var timeLabel: UILabel = UILabel(title: "21:56", fontSize: 12, color: UIColor.lightGrayColor())
    private lazy var sourceLabel: UILabel = UILabel(title: "iPhone 6s", fontSize: 12, color: UIColor.lightGrayColor())
    // 认证类型
    private lazy var verifiedTypeImage: UIImageView = UIImageView(image: UIImage(named: "avatar_enterprise_vip"))
    // 微博正文
    private lazy var contentLabel: UILabel  = UILabel(title: "敌军还有三十秒到达战场,碾碎他们!", fontSize: 14, color: UIColor.darkGrayColor(),margin: StatusCellMargin)
    // 配图视图
    private lazy var pictureView: StatusCellPictureView = StatusCellPictureView()
    
    
}
